//
//  CouponListTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/8.
//  Copyright © 2018年 四川中农. All rights reserved.
//



import UIKit

typealias BackCouponValue = (CouponModel)->Void

class CouponListTableViewCell: UITableViewCell {
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var centerLineImage: UIImageView!
    @IBOutlet weak var rightLabel: UILabel!
    @IBOutlet weak var moneyLabel: UILabel!
    @IBOutlet weak var rmbLabel: UILabel!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var seletedBtn: UIButton!
    @IBOutlet weak var shadowLabel: UILabel!
    @IBOutlet weak var shadowView: UIView!
    
    var seleCouponClosure:BackCouponValue!
    
    var model:CouponModel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        self.shadowView.backgroundColor = UIColor.init(hexColor: "000000", alpha: 0.8)
        self.bgView.setCornerRadio(radio: 5, isMask: true)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func reload(withModel model:CouponModel,isSeleCoupon:Bool,money:Double){
        self.model = model
        self.moneyLabel.text = "\(model.jian)"
        self.rightLabel.text = "满" + "\(model.man)" + "元可用"
        self.timeLabel.text = "请在" + (model.endTime.timeStampToString(timeFormat: "YYYY-MM-dd HH:mm")) + "前使用"
        self.seletedBtn.isHidden = !isSeleCoupon
        self.shadowView.isHidden = true
        if isSeleCoupon && money < model.man{
            self.shadowView.isHidden = false
            var str = String.init(format: "%.2f", model.man - money)
            str = "还差" + str + "元可用"
            self.shadowLabel.attributedText = Utils.changeLabelTextFontSize(normalString: str, changeString: "\(model.man - money)".getPriceInteger(), font: UIFont.systemFont(ofSize: 20))
        }
    }
    
    func disabledStyle(){
        self.bgView.backgroundColor = UIColor.init(hexColor: "#cccccc")
        self.centerLineImage.image = UIImage.init(named: "fenge")
        self.moneyLabel.textColor = UIColor.init(hexColor: "#fefefe")
        self.rightLabel.textColor = UIColor.init(hexColor: "#fefefe")
        self.timeLabel.textColor = UIColor.init(hexColor: "#fefefe")
        self.rmbLabel.textColor = UIColor.init(hexColor: "#fefefe")
    }
    
    func normalStyle(){
        self.bgView.backgroundColor = UIColor.init(hexColor: "#f7c201")
        self.centerLineImage.image = UIImage.init(named: "youhuiquan_fenge")
        self.moneyLabel.textColor = UIColor.init(hexColor: "#000000")
        self.rightLabel.textColor = UIColor.init(hexColor: "#000000")
        self.timeLabel.textColor = UIColor.init(hexColor: "#000000")
        self.rmbLabel.textColor = UIColor.init(hexColor: "#000000")
    }
    
    @IBAction func seleButtonClick(_ sender: UIButton) {
        if self.seleCouponClosure != nil {
            self.seleCouponClosure(self.model)
        }
    }
    
}
